package com.wei.duowan.bbs.utils;

import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;

import com.wei.duowan.bbs.App;

/**
 * 作者：赵若位
 * 时间：2019/10/23 14:44
 * 联系方式：1070138445
 * 功能：
 */
public class DrawableUtils
{
    private static final String TAG = DrawableUtils.class.getSimpleName();

    public static final String TYPE_DRAWABLE = "drawable";
    public static final String TYPE_MIPMAP = "mipmap";


    public static int getIntRes(@Nullable String paramterString)
    {
        return getIntRes(paramterString, TYPE_MIPMAP);
    }

    /*根据文件名字获取图片ID*/
    public static int getIntRes(@Nullable String paramterString, @Nullable String type)
    {
        return (TextUtils.isEmpty(paramterString) || TextUtils.isEmpty(type)) ? 0 :
                App.getResource().getIdentifier(paramterString, type, Configuration.getInstance().getPackName());
    }

    /*根据图片名字获取资源ID*/
    public static Drawable getDrawableRes(@Nullable String paramterString)
    {
        int intRes = getIntRes(paramterString);
        Log.e(TAG, "getDrawableRes: " + intRes);
        return intRes != 0 ? App.getResource().getDrawable(intRes) : null;
    }
}
